package com.example.day10.homework;

import java.util.ArrayList;
import java.util.List;

public class MailAddressArrayList {
    private List<MailAddress> addressList;

    public MailAddressArrayList() {
        addressList=new ArrayList<>();
    }

    public  void add(MailAddress mailAddress){

        addressList.add(mailAddress);
    }
    public  void  display(){
        for (MailAddress mailAddress : addressList) {
            System.out.println(mailAddress.toString());
        }
    }
    //给定用户名返回改客户所有邮件
    public List<MailAddress> showRess(String name){
        List<MailAddress> lists=new ArrayList<>();
        for(int i=0;i<addressList.size();i++){
            if (addressList.get(i).getName().equals(name)){
                lists.add(addressList.get(i));
            }
        }

        return  lists;
    }
}

class ClassMain{
    public static void main(String[] args) {
        MailAddressArrayList mailAddressArrayList=new MailAddressArrayList();
        MailAddress m1=new MailAddress("Jennie",12345678901L,"南京路","上海浦东","上海","中国","CN 86");
        MailAddress m2=new MailAddress("Lisa",99966612345L,"中山路","上海浦东","上海","中国","CN 86");
        MailAddress m3=new MailAddress("Rose",11111222333L,"广东路","上海浦东","上海","中国","CN 86");
        MailAddress m4=new MailAddress("Rose",11111222333L,"新民路","釜山","首尔","韩国","KR 82");
        mailAddressArrayList.add(m1);
        mailAddressArrayList.add(m2);
        mailAddressArrayList.add(m3);
        mailAddressArrayList.add(m4);
        mailAddressArrayList.display();
        System.out.println("============================");
        //给定客户名返回邮件信息并且打印
        List<MailAddress> list = mailAddressArrayList.showRess("Rose");
        for (MailAddress mailAddress : list) {
            System.out.println(mailAddress.toString());
        }

    }
}
